#include "finddialog.h"
#include "ui_finddialog.h"

FindDialog::FindDialog(QWidget *parent) : QDialog(parent),
                                          ui(new Ui::FindDialog)
{
    ui->setupUi(this);
    setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
    setWindowTitle("查找");
    connect(ui->lineEdit, QLineEdit::textChanged, this, &FindDialog::textChangeSlot);
}

FindDialog::~FindDialog()
{
    delete ui;
}

void FindDialog::on_findnextButton_clicked()
{
    bool checkbox1 = ui->uplowcheckBox->isChecked(); //大小写
    bool checkbox2 = ui->loopcheckBox->isChecked();  //循环
    QString value = ui->lineEdit->text().trimmed();
    bool isUp = false;
    if (ui->upradioButton->isChecked())
        isUp = true;
    if (value.isEmpty())
    {
        this->showMessage("请输入查找关键字");
        return;
    }
    //发送信号
    emit this->findtext(value, checkbox1, checkbox2, isUp);
}

void FindDialog::on_cancelButton_clicked()
{
    this->close();
}

void FindDialog::textChangeSlot()
{
    if (ui->lineEdit->text().trimmed().isEmpty())
        ui->findnextButton->setEnabled(false);
    else
        ui->findnextButton->setEnabled(true);
}

void FindDialog::showMessage(QString title)
{
    QMessageBox box(QMessageBox::Question, "记事本 - 查找", title, QMessageBox::Ok);
    box.setIcon(QMessageBox::NoIcon);
    box.button(QMessageBox::Ok)->setText("确定");
    box.setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint);
    box.exec();
}
